package com.bdqn.Di2Zhan;//package com.bdqn;
//
//import org.w3c.dom.Node;
//import org.w3c.dom.NodeList;
//import org.xml.sax.SAXException;
//
//import javax.swing.text.Document;
//import javax.swing.text.Element;
//import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.DocumentBuilderFactory;
//import javax.xml.parsers.ParserConfigurationException;
//import javax.xml.transform.OutputKeys;
//import javax.xml.transform.Transformer;
//import javax.xml.transform.TransformerFactory;
//import javax.xml.transform.dom.DOMSource;
//import javax.xml.transform.stream.StreamResult;
//import java.io.FileOutputStream;
//import java.io.IOException;
//
//public class PhoneInfo {
//    Document doc = null;
//
//    public void getDocument(){
//        DocumentBuilderFactory dbc = DocumentBuilderFactory.newInstance();
//
//        try {
//            DocumentBuilder db = dbc.newDocumentBuilder();
//
//            Document doc = (Document) db.parse("src/收藏信息.xml");
//        }catch (ParserConfigurationException e){
//            e.printStackTrace();
//        }catch (SAXException e){
//            e.printStackTrace();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//    public void showInfo(){
//        Element brandElement = doc.createElement("Brand");
//        brandElement.setAttribute("name","三星");
//        //添加父子关系
//        Element phoneElement = (Element) doc.getElementsByTagName("PhoneInfo").item(0);
//
//        phoneElement.appendChild(brandElement);
//        //保存XML文件
//        TransformerFactory transformerFactory = transformerFactory.newInstance();
//        Transformer transformer = transformerFactory.newTransformer();
//        DOMSource domSource = new DOMSource(doc);
//
//        //设置编码
//        transformer.setOutputProperty(OutputKeys.ENCODING,"gb2312");
//        StreamResult result = new StreamResult(new FileOutputStream("src/信息收藏.xml"));
//
//        former.transform(domSource , result);
//    }
//
//    public static void main(String[] args) {
//        PhoneInfo parse = new PhoneInfo();
//        parse.getDocument();
//        parse.showInfo();
//    }
//}
